package com.collection;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListDemo1 {
    public static void main(String[] args) {
        //实例化内容
        ArrayList<Student> studentArray = new ArrayList<Student>();
        addStudent(studentArray);
        addStudent(studentArray);
        addStudent(studentArray);

        for (int i = 0; i < studentArray.size(); i++) {
            Student s = studentArray.get(i);
            System.out.println(s.getName() + "," + s.getAge());
        }
    }

    /**
     * @author 添加学生的内容
     * @param studentArray 集合列表
     */
    public static void addStudent(ArrayList<Student> studentArray) {
        //键盘录入内容的的实例化对象展示
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入学生姓名");
        String name = scanner.nextLine();
        System.out.println("输入学生年龄");
        int age = scanner.nextInt();

        Student student = new Student();
        student.setName(name);
        student.setAge(age);
        studentArray.add(student);
    }
}

